//
// Created by yyl on 2018/6/6.
//

#ifndef MYMUSIC_YYL_CALLBACK_H
#define MYMUSIC_YYL_CALLBACK_H

#include "yyl_log.h"

#define THREAD_MAIN 0
#define THREAD_CHILD 1

#define EVENT_STATE_PARPARED 0
#define EVENT_STATE_PLAY 1
#define EVENT_STATE_TIME 2
#define EVENT_STATE_COMPLETE 3

#define EVENT_STATE_PCM_DB 4  //pcm 分贝值

#define EVENT_STATE_PCM_BUFFER 5
#define EVENT_STATE_ERROR 10


#define EVENT_FALSE 0
#define EVENT_TRUE 1

class CallJava {


public:
    JavaVM *javaVM;
    JNIEnv *jniEnv;
    jobject yPlayer;
    jmethodID javaOnCallBackEvent;
    jmethodID javaOnCallPcmToAAC;
    jmethodID javaOnCallRenderYUV;
    jmethodID javaOnCallSupportHardware;
    jmethodID javaOnCallInitMediaCodec;
    jmethodID javaOnCalldecodeAVPacket;
public:
    CallJava(JNIEnv *env, jobject player);

    ~CallJava();

    void onCallBackEvent(int mainThread, int event, int arg1, int arg2);

    void onCallPcmToAAC(int mainThread, int event, int size, void *buffer);

    void onCallRenderYUV(int width, int height, uint8_t *frameY, uint8_t *frameU, uint8_t *frameV);

    //是否支持硬件加速
    bool onCallIsSupportHardware(const char *ffcodecName);

    //init硬件加速
    bool
    onCallInitMediacodec(const char *mimeType, int width, int height, int csd0_size, int csd1_size,
                         uint8_t *csd_0, uint8_t *csd_1);

    void onCallDecodeAVPacket(int datasize, uint8_t *data);
};


#endif //MYMUSIC_YYL_CALLBACK_H
